import flash.events.Event;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.geom.Matrix;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.text.TextFormatAlign;

import Images;
class PauseMenuEvent extends Event{
 
	public function new(customEventString:String){

	super(customEventString, true, false);

    }
}

class PauseMenu extends Sprite
{
private var VolumeButton:Sprite;
private var PrevButton:Sprite;
private var NextButton:Sprite;
private var SoundEffectsButton:Sprite;
private var Text:TextField;
private var isSaved:TextField;
// public var volume:Bool;
// public var sound:Bool;

  public function new()
  {
  super();
  //Resize Image
  var background = new Sprite();
    background.graphics.lineStyle(1);
    background.graphics.beginFill(0xFFFFFF);
    background.graphics.drawRect(0, 0,Constants.flashWidth,Constants.flashHeight);
    background.alpha = 0.5;
    background.graphics.endFill();
    background.x = 0; background.y = 0;
  //End Resize
  addChild(background);

 Text = new TextField();
    
  Text.x = 0; Text.y = 420;
  Text.width = 800; Text.height = 420;
  addChild(Text);
  Text.multiline = true;
  Text.selectable = false;
  var myFormat:TextFormat = new TextFormat();
  myFormat.size = 22;
  myFormat.align = TextFormatAlign.CENTER;
  Text.defaultTextFormat = myFormat;
  
  Text.htmlText = "Pause Menu (Press P to UnPause)";

//   PrevButton  = new Sprite();
//   PrevButton.graphics.beginBitmapFill(new Prev());
//   PrevButton.graphics.drawRect(0, 0, 60 ,113);
//   PrevButton.x = 195;
//   PrevButton.y = 70;
//   PrevButton.buttonMode = true;
//   PrevButton.addEventListener(MouseEvent.CLICK, onPrevButtonClick);
  //addChild(PrevButton);

  VolumeButton  = new Sprite();
  VolumeButton.graphics.beginBitmapFill(new Volume());
  VolumeButton.graphics.drawRect(0, 0, 113 ,113);
  VolumeButton.x = 300;
  VolumeButton.y = 310;
  VolumeButton.buttonMode = true;
  VolumeButton.addEventListener(MouseEvent.CLICK, onVolumeButtonClick);
  addChild(VolumeButton);

//   NextButton  = new Sprite();
//   NextButton.graphics.beginBitmapFill(new Next());
//   NextButton.graphics.drawRect(0, 0, 60 ,113);
//   NextButton.x = 385;
//   NextButton.y = 70;
//   NextButton.buttonMode = true;
//   NextButton.addEventListener(MouseEvent.CLICK, onNextButtonClick);
//  addChild(NextButton);

  var QuitButton  = new Sprite();
  QuitButton.graphics.lineStyle(1);
  QuitButton.graphics.beginFill(0x0000000);
  QuitButton.graphics.drawCircle(45, 45,48);
  QuitButton.graphics.endFill();
  QuitButton.x = 420;
  QuitButton.y = 320;
  QuitButton.buttonMode = true;
  var QuitText = new TextField();
  QuitText.htmlText = "<font color='#FFFFFF' size='32'>Quit</font>";
  QuitText.x = 13;QuitText.y = 20;
  QuitText.selectable =  false;
  QuitButton.addChild(QuitText);
  QuitButton.addEventListener(MouseEvent.CLICK, onQuitButtonClick);
  addChild(QuitButton);

  var SaveButton  = new Sprite();
  SaveButton.graphics.lineStyle(1);
  SaveButton.graphics.beginFill(0x0000000);
  SaveButton.graphics.drawCircle(45, 45,48);
  SaveButton.graphics.endFill();
  SaveButton.x = 300;
  SaveButton.y = 200;
  SaveButton.buttonMode = true;
  var SaveText = new TextField();
  SaveText.htmlText = "<font color='#FFFFFF' size='32'>Save</font>";
  SaveText.x = 13;SaveText.y = 20;
  SaveText.selectable =  false;
  SaveText.mouseEnabled =  false;
  SaveButton.addChild(SaveText);
  SaveButton.addEventListener(MouseEvent.CLICK, onSaveButtonClick);
  addChild(SaveButton);

  isSaved = new TextField();
  isSaved.htmlText = "<font color='#000000' size='32'>Saved</font>";
  isSaved.x = 430;isSaved.y = 220;
  isSaved.selectable =  false;
  isSaved.alpha = 0;
  addChild(isSaved);
  this.addEventListener(Event.ENTER_FRAME, fadeOut);

  }

function fadeOut(e:Event){
   if (isSaved.alpha > 0)
      {
	isSaved.alpha -= 0.02;
      }
}
public function renderVolume(volume:Bool)
{
  if(volume)
  {
  VolumeButton.graphics.clear();
  VolumeButton.graphics.beginBitmapFill(new Volume());
  VolumeButton.graphics.drawRect(0, 0, 113 ,113);
  }
  else
  {
  VolumeButton.graphics.clear();
  VolumeButton.graphics.beginBitmapFill(new VolumeMuted());
  VolumeButton.graphics.drawRect(0, 0, 113 ,113);
  }

}

private function onQuitButtonClick(event:MouseEvent)  {
  dispatchEvent(new PauseMenuEvent("Quit"));
}

private function onSaveButtonClick(event:MouseEvent)  {
  isSaved.alpha =1;
  dispatchEvent(new PauseMenuEvent("Save"));
}

private function onVolumeButtonClick(event:MouseEvent)  {
  dispatchEvent(new PauseMenuEvent("VolumeToggle"));
}

private function onPrevButtonClick(event:MouseEvent)  {
  dispatchEvent(new PauseMenuEvent("PrevTrack"));
}

private function onNextButtonClick(event:MouseEvent)  {
  dispatchEvent(new PauseMenuEvent("NextTrack"));
}
}